<?php
class CPreorder extends Zend_Db_Table{
	protected $_name;
	
	protected $_primary;
	
	public function __construct(){
	
		$this->_name=R_PRE."preorder";
	
		$this->_primary="id";
	
		parent::__construct();
	
	}
	public function createPreorder($data){
		$id=$this->insert($data);
		
		return id;
	}
	public function getPreorder($id){
		$db = $this->getAdapter();
		$select = $db->select();
		
		$select->from($this->_name,'*');
		
		$select->where($this->_name.'.id = ? ',$id);
		return $db->fetchRow($select);
	}
	public function checkPreorder($uid){
		$db = $this->getAdapter();
		$select = $db->select();
		
		$select->from($this->_name,'*');
		
		$select->where($this->_name.'.uid = ? ',$uid)->where($this->_name.'.itemid = ? ',$itemid);
		
		return $db->fetchRow($select);
	}
	public function getCertainOrder($id){
		$db = $this->getAdapter();
		$select = $db->select();
		
		$select->from($this->_name,'*');
		
		$select->where($this->_name.'.id = ? ',$id);

		return $db->fetchRow($select);
	}
	public function getPreorderdetail($uid=''){
		$db = $this->getAdapter();
		$select = $db->select();
		if(!empty($uid)){
			$select->where($this->_name.'.uid = ? ',$uid);
		}
		$select->order('orderid');
		
		$select->from($this->_name,'*');
		
		//$select->j
			
		return $db->fetchAll($select);
	}
	public function getOrderByitemid($itemid){
		$db = $this->getAdapter();
		$select = $db->select();
		
		$select->from($this->_name,'*');
		
		$select->where($this->_name.'.itemid = ? ',$itemid);
		//$select->j
		return $db->fetchRow($select);
	}
	
	public function getOrdersByitemid($itemid){
		$db = $this->getAdapter();
		$select = $db->select();
		
		$select->from($this->_name,'*');
		
		$select->where($this->_name.'.itemid = ? ',$itemid);
		//$select->j
		return $db->fetchAll($select);
	}
	
	public function showpreorderdetail(){
		$db = $this->getAdapter();
		$select = $db->select();
		
		$select->from($this->_name,'*');
		$select->joinLeft('zcshop_orders', 'zcshop_preorder.itemid = zcshop_products.itemid', '*')->join('zcshop_product_price', 'zcshop_product_price.itemid = zcshop_products.itemid', '*');
		//array('zcshop_orders.')
		$select->order('zcshop_orders.orderid');
		//$select->j
		return $db->fetchRow($select);
	}
	public function updatepreorder($id,$relate_orderid){
		$db = $this->getAdapter();
		
		
		$db->query("update zcshop_preorder set relate_orderid='$relate_orderid' where id='$id'");
	}
}